package com.example.scoprimi;

import com.example.scoprimi.R;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.SearchManager;
import android.content.ClipData.Item;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;

public class ValutaDati extends Activity {
	
	

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.valutadati);
		
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		getOverflowMenu();
		
		
	    getActionBar().setDisplayHomeAsUpEnabled(true);
	    setTitle("");
	    getActionBar().setIcon(R.drawable.ic_home_up);
	    
	    //EditText text = (EditText)findViewById(R.id.action_search);
	    //text.setHint(R.string.queryHint);

	    
	    
	    
	
		
	}

	// inflate for action bar
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main2, menu);
        MenuItem menuItem = menu.findItem(R.id.action_search);
        
        SearchView searchView = (SearchView) menuItem.getActionView();
        searchView.setQueryHint("Cerca per indirizzo...");
        int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
        View searchPlate = searchView.findViewById(searchPlateId);
        if (searchPlate!=null) {
            searchPlate.setBackgroundColor(Color.TRANSPARENT);
            int searchTextId = searchPlate.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
            TextView searchText = (TextView) searchPlate.findViewById(searchTextId);
            if (searchText!=null) {
	            searchText.setTextColor(Color.WHITE);
	            searchText.setHintTextColor(Color.WHITE);
            }
        }
        return true;
	}
		/* Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		
		// Associate searchable configuration with the SearchView
	    SearchManager searchManager =
	           (SearchManager) getSystemService(Context.SEARCH_SERVICE);
	    SearchView searchView =
	            (SearchView) menu.findItem(R.id.action_search).getActionView();
	    searchView.setSearchableInfo(
	            searchManager.getSearchableInfo(getComponentName()));
	    
		return true;
	}*/
	
	// handle click events for action bar items
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

	    switch (item.getItemId()) {
	    
	        case R.id.action_search:
	            //showToast("Tasto cerca");
	            return true;
	        
	        case R.id.copyLink2:
	        	Intent intent = new Intent(this, Valuta.class);
	            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	            startActivity(intent);
	            return true;
		    
	        case R.id.action_settings:
	        	showToast("Tasto settings");
	            return true;
	            
	        
	            
	        case android.R.id.home:
	        	Intent intenthome = new Intent(this, Home.class);
	    	    intenthome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	            startActivity(intenthome);
	            return true;
	        default:
	            return super.onOptionsItemSelected(item);
	            
	        
	            
	        
	    }
	}
	
	// put the other two menu on the three dots (overflow)
	private void getOverflowMenu() {

	    try {
	    	
	       ViewConfiguration config = ViewConfiguration.get(this);
	       java.lang.reflect.Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
	       if(menuKeyField != null) {
	           menuKeyField.setAccessible(true);
	           menuKeyField.setBoolean(config, false);
	       }
	   } catch (Exception e) {
	       e.printStackTrace();
	   }
	    
	 }
	
	// so that we know something was triggered
	public void showToast(String msg){
		Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
	}
	
	
	
	
	}
	

